package org.agile2soft.nexoma.tapestry.components.locale;

import java.util.Locale;

import org.agile2soft.nexoma.tapestry.encoder.LocaleEncoder;
import org.agile2soft.nexoma.tapestry.model.LocaleSelectModel;
import org.agile2soft.nexoma.tapestry.services.SupportedLocales;
import org.apache.tapestry5.SelectModel;
import org.apache.tapestry5.ValueEncoder;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.PersistentLocale;

public class LocaleSwitcher {

    @Inject
    private SupportedLocales supportedLocales;

    @Inject
    private PersistentLocale persistentLocale;

    @Inject
    private Messages messages;

    public Locale getSelectedLocale () {
        return null;
    }

    public void setSelectedLocale(Locale locale) {
        if ( locale!=null ) {
            persistentLocale.set(locale);
        }
    }

    public SelectModel getLocaleModel() {
        return new LocaleSelectModel(supportedLocales.getSupportedLocales(),messages);
    }

    public ValueEncoder<Locale> getLocaleEncoder() {
        return new LocaleEncoder();
    }

}